package com.weng.platform.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.weng.framework.core.constants.ResultCodeEnum;
import com.weng.framework.core.exception.GlobalServiceException;
import com.weng.framework.core.model.ResponseData;
import com.weng.framework.dao.mybatis.model.page.PageModel;
import com.weng.framework.dao.mybatis.service.BaseServiceImpl;
import com.weng.platform.article.entity.ArticleContent;
import com.weng.platform.article.mapper.ArticleContentMapper;
import com.weng.platform.article.service.IArticleContentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Arrays;


/**
 * 新闻资讯内容表 服务实现类
 *
 * @author wenghui
 * @date 2019-11-29 14:48:05
 *
 */ 
@Slf4j
@Service
public class ArticleContentServiceImpl extends BaseServiceImpl<ArticleContentMapper, ArticleContent> implements IArticleContentService {
	@Autowired
	private ArticleContentMapper contentMapper;
	

	/**
	 * 分页查询新闻资讯内容表
	 * @return
	 */
	@Override
	public IPage<ArticleContent> list(Integer pageNo,Integer pageSize) {
		QueryWrapper<ArticleContent> qw = new QueryWrapper<ArticleContent>();
		IPage<ArticleContent> page = new PageModel<ArticleContent>(pageNo,pageSize);
		return contentMapper.selectPage(page,qw);
	}


	/**
	 * 获取单个新闻资讯内容表
	 * @param id
	 * @return
	 */
	@Override
	public ArticleContent getById(Serializable id) {
		return super.getById(id);
	}

	/**
	 * 新增单个新闻资讯内容表
	 * @param content
	 * @return
	 */
	@Override
	public ArticleContent add(ArticleContent content) throws GlobalServiceException {
		
		contentMapper.insert(content);
		return content;
	}

	/**
	 * 更新单个新闻资讯内容表
	 * @param content
	 * @return
	 * @throws GlobalServiceException
	 */
	@Override
	public int update(ArticleContent content) throws GlobalServiceException {
		
		return contentMapper.updateById(content);

	}


	@Override
	public ResponseData removeByIds(String ids) {
		String[] contentIds = ids.split(",");
		boolean flag = this.removeByIds(Arrays.asList(contentIds));
		if (flag) {
			return ResponseData.success();
		} else {
			throw new GlobalServiceException(ResultCodeEnum.DATABASE_OPERATE_EXCEPTION.getCode(), "删除新闻资讯内容表：" + Arrays.asList(contentIds).toString() + ResultCodeEnum.DATABASE_OPERATE_EXCEPTION.getMessage());
		}
	}

}
